package com.jiazhong.boot.exception.handler;

import com.jiazhong.boot.commons.util.JsonResult;
import com.jiazhong.boot.commons.util.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

// 这个是一个异常处理类
@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(ArithmeticException.class)
    public JsonResult arithmeticException(Throwable e) {
        log.error("代码出现了异常：{}", e.getMessage());
        return ResultTool.fail(501, e.getMessage());
    }

    @ExceptionHandler(LoginFailException.class)
    public JsonResult loginFailException(Throwable e) {
        log.error("代码出现了异常：{}", e.getMessage());
        return ResultTool.fail(502, e.getMessage());
    }
}
